import 'package:Flutter_Demo/core/model/meal_model.dart';
import 'package:Flutter_Demo/core/viewmodel/favor_view_model.dart';
import 'package:flutter/material.dart';
import 'package:provider/provider.dart';

import 'detail_content.dart';

class MYDetailScreen extends StatelessWidget {

  static const String routeName = "/detail";

  @override
  Widget build(BuildContext context) {

    final meal = ModalRoute.of(context).settings.arguments as MYMealModel;

    return Scaffold(
      appBar: AppBar(
        title: Text(meal.title),
      ),
      body: MYDetailContent(meal),
      floatingActionButton: Consumer<MYFavorViewModel>(
        builder: (ctx, favorViewModel, child) {
          final favorData = favorViewModel.isFavor(meal) ? Icons.favorite : Icons.favorite_border;
          final iconColor = favorViewModel.isFavor(meal) ? Colors.red : Colors.black;
          return FloatingActionButton(

            child: Icon(favorData, color: iconColor,),
            onPressed: () {
              favorViewModel.handleMeal(meal);
            },
          );
        },
      )
    );
  }
}
